package com.woniu.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniu.entity.response.ResponseEntity;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @BelongsProject: phase3project
 * @BelongsPackage: com.woniu.util
 * @Author: hyl
 * @CreateTime: 2022-08-30  14:37
 * @Description: TODO
 * @Version: 1.0
 */
public class ResponseEntityUtil {
    public static void sendResponseEntity(HttpServletResponse response, ResponseEntity responseEntity) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(responseEntity);
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = response.getWriter();
        writer.println(json);
        writer.close();
    }
}
